package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

//@Controller//代表该类是一个controller层，项目启动时该类交给Sprijng容器管理
@RestController //@Controller+ @ResponseBody
public class DemoController {
    //访问路径：http://localhost:8080/WebApp_SpringMvc/regHandle.do
    @PostMapping("/user/regHandle.do")
    public String regHandle(String username,String password,int age,String email){
        System.out.println("username:"+username+"password:"+password+"age:"+age+"email:"+email);
        return "Ok";
    }
    //请求路径：http://localhost:8080/WebApp_SpringMvc/showReg.do
    @GetMapping("/user/showReg.do")
    public ModelAndView showReg(){
        System.out.println("showRe()执行了");
        return new ModelAndView("reg");
    }

    //访问路径：http://localhost:8080/WebAPP_SpringMvc/showHello.do
    @GetMapping("showHello.do")
    public ModelAndView showHello(){
        return new ModelAndView("hello");
    }

    /**
     * 当我们发送请求thhp://localhost:8080/WebApp_SpringMvc/hello.do
     * @return
     */
    @GetMapping("hello.do")
    //@ResponseBody //默认返回的是页面的名字，如果返回的不是页面，需要使用该注解进行转换json串
    public String demo(){
        System.out.println("controller层demo()执行啦！");
        return "你好 SpringMVC";  //中文乱码
    }

}
